#coding=utf-8
from stockdb.misc import *
i = sess.query(SIndex).filter_by(name='上证指数').one()

class SCI(object):
    '''
    SCI:SSE Composite Index(上证指数)
    '''
    def __init__(self, date):
        self.td = i.find_td(date)
        self.p = self.td.price
        self._get_bstats()
        
    def _get_bstats(self):    
        self.bs = sess.query(TDStats).filter_by(tradeday_id=self.td.id).\
                      one()
    
    def get_pre(self):
        if self.td.pre:
            pd = self.td.pre.date.isoformat()
            return SCI(pd)
        else:
            return None
    pre = property(fget=get_pre)
    
    def get_next(self):
        if self.td.next:
            nd = self.td.next.date.isoformat()
            return SCI(nd)
        else:
            return None
    next = property(fget=get_next)
            
